#include    <unistd.h>
#include    <stdlib.h>
#include    <stdio.h>

int globvar =    6;
char buf[] =    "a write to stdout\n";

int main (int argc,char **argv)
{
    int     var;
    pid_t   pid;
    var = 88;
    if(    write(STDOUT_FILENO,buf,sizeof(buf)-1)  != sizeof(buf) -1   )
        perror(" write error \n");

    printf("befor fork \n");
    pid = fork();
  //  if( (pid = fork())  <0 )
  if ( pid <0 )
    {
        perror( "fork error \n");
    }
    else if ( pid == 0 ) //子进程返回值为0
    {
        globvar ++;
        var++;
    }
    else
    {
        sleep(2);
    }

    printf("\r\npid=%ld ,   glob = %d, var=%d\n",(long)getpid(),globvar,var);
    

    exit(0);
}